package test05;

public class Test45 {
}
class Animal {
    private String name;

    public Animal(String name) {
        this.name = name;
    }

    public Animal() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

class Dog extends Animal {
    public Dog(String name) {
        super(name);
    }

    public Dog() {
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public void setName(String name) {
        super.setName(name);
    }
}

class Cat extends Animal {
    public Cat() {
    }

    public Cat(String name) {
        super(name);
    }

    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public void setName(String name) {
        super.setName(name);
    }
}

class TestAnimal {
    public static void main(String args[]) {
        Animal[] as = new Animal[] { new Dog("Pluto"), new Cat("Tom"), new Dog("Snoopy"), new Cat("Garfield") };
        Dog[] dogs = getAllDog(as);
        for (int i = 0; i <= dogs.length; i++) {
            System.out.println(dogs[i].getName());
        }
    }

    public static Dog[] getAllDog(Animal[] as) {
        int count=0;
        for (int i = 0; i < as.length; i++) {
            if(as[i] instanceof Dog){
                count++;
            }
        }
        Dog[] dogs=new Dog[count];
        int j=0;
        for(int i=0;i<as.length;i++,j++){
            if(as[i] instanceof Dog){
                dogs[j]=(Dog)as[i];
            }
        }
        return dogs;
    }
}
